import { createRouter, RouteRecordRaw, createWebHashHistory } from 'vue-router';
import Layout from '@/layout';

// 看作是异步获取路由
export const asyncRoutes: Array<RouteRecordRaw> = [
    {
        path: '/documentation',
        component: Layout, // 布局组件作为一级路由
        redirect: '/documentation/index',
        meta: {
            title: 'Documentation',
            icon: 'documentation'
        },
        children: [
            {
                path: 'index',
                name: 'Documentation',
                component: () => import(/* webpackChunkName: "documentation" */ '@/views/documentation'),
                meta: {
                    title: 'Documentation',
                    icon: 'documentation'
                }
            }
        ]
    },
    {
        path: '/guide',
        component: Layout,
        redirect: '/guide/index',
        meta: {
            title: 'Guide',
            icon: 'guide'
        },
        children: [
            {
                path: 'index',
                name: 'Guide',
                component: () => import(/* webpackChunkName: "guide" */ '@/views/guide/index.vue'),
                meta: {
                    title: 'Guide',
                    icon: 'guide'
                }
            }
        ]
    },
    {
        path: '/system',
        component: Layout,
        redirect: '/system/user',
        meta: {
            title: 'System',
            icon: 'lock'
        },
        children: [
            {
                path: 'menu',
                component: () => import(/* webpackChunkName: "menu" */ '@/views/system/menu'),
                meta: {
                    title: 'Menu Management',
                    icon: 'list'
                }
            },
            {
                path: 'role',
                component: () => import(/* webpackChunkName: "role" */ '@/views/system/role'),
                meta: {
                    title: 'Role Management',
                    icon: 'list'
                }
            },
            {
                path: 'user',
                component: () => import(/* webpackChunkName: "user" */ '@/views/system/user'),
                meta: {
                    title: 'User Management',
                    icon: 'list'
                }
            }
        ]
    }, {
        path: "/external-link",
        component: Layout,
        children: [
            {
                path: "https://www.baidu.com/",
                redirect: "/",
                meta: {
                    title: '百度',
                    icon: 'list'
                }
            },
        ],
        meta: {
            title: "External Link",
            icon: "link",
        },
    }
]

export const routes: RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/dashboard',
        component: Layout,
        children: [
            {
                path: 'dashboard',
                component: () => import(/* webpackChunkName: "Dashboard" */'@/views/dashboard')
            },
            { path: 'about', component: () => import(/* webpackChunkName: "About" */'@/views/About/index.vue') }
        ],
        meta: {
            title: 'home',
            icon: 'dashboard'
        }
    },
    ...asyncRoutes
];

export default createRouter({
    history: createWebHashHistory(),
    routes
});
